package 网络编程.UDP协议.组播;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class 组播发送数据 {
    public static void main(String[] args) throws IOException {
        //1.创建组播的发送端MulticastSocket
        MulticastSocket ms=new MulticastSocket();

        //2.对数据进行打包
        String s="13324";
        byte[] bytes = s.getBytes();
        //创建要发送的组播地址
        InetAddress address =InetAddress.getByName("224.0.0.2");
        int port=10000;
        DatagramPacket dp=new DatagramPacket(bytes,bytes.length,address,port);

        //3.发送数据
        ms.send(dp);

        //4.释放资源
        ms.close();
    }
}
